#pragma once
#include <iostream>
#include <string>

using namespace std;

const int defaultvalue = 0;

enum
{
    ok = 0,
    div_zero,
    mod_zero,
    unknow,
};

const string opers = "+-*/%)(&";

class Task
{
public:
    Task()
    {}
    Task(int x, int y, char op)
        :data_x(x)
        ,data_y(y)
        ,oper(op)
    {}

    void Run()
    {
        switch(oper)
        {
            case '+':
                result = data_x + data_y;
                break;
            case '-':
                result = data_x - data_y;
                break;
            case '*':
                result = data_x * data_y;
                break;
            case '/':
                {
                    if(data_y == 0)
                    {
                        code = div_zero;
                    }
                    else
                    {
                        result = data_x / data_y;
                    }
                }
                break;
            case '%':
                {
                    if(data_y == 0)
                    {
                        code = mod_zero;
                    }
                    else
                    {
                        result = data_x % data_y;
                    }
                }
                break;
            default:
                code = unknow;
                break;
        }
    }

    string PrintTask()
    {
        string s;
        s += to_string(data_x);
        s += oper;
        s += to_string(data_y);
        s += "=?";

        return s;
    }

    string PrintResult()
    {
        string s;
        s += to_string(data_x);
        s += oper;
        s += to_string(data_y);
        s += " = ";
        s += to_string(result);
        s += " [";
        s += to_string(code);
        s += "]";

        return s;
    }

    ~Task()
    {}
private:
    int data_x;
    int data_y;
    char oper; // +-*/%

    int result;
    int code; // 结果码：0，结果可信。！0，结果不可信
};